package lesson12;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;

public class HashMapNotSafe {

    public static void main(String[] args) {
        final Map<Integer, String> map = new HashMap<>();
        final Integer targetKey = 0b1111_1111_1111_1111;
        final String targetValue = "v";
        map.put(targetKey, targetValue);
        new Thread(() -> {
            IntStream.range(0, targetKey).forEach(key -> map.put(key, ""));
        }).start();

        while (true){
            //System.out.println("map size : " + map.size());
            if(map.containsKey(targetKey)){
                System.out.println("targetValue : " + targetValue);
            }
            if(null == map.get(targetKey)){
                throw new RuntimeException("HashMap is not thread safe.");
            }
        }
    }
}
